<?php
class Project_Photo_Table extends CF_DbTable_Table
{
	protected $_name = 'photos';

	public function addProductPhoto(array $photoData){
		$data = array(
			'product_id' => $photoData['product_id'],
			'link'       => $photoData['link']
		);
		$this->insert($data);

	}

	public function editProductPhoto(array $photoData){

		$data = array(
			//'product_id' => (int)$photoData['product_id'],
			'link'       => $photoData['link']
		);
		$where = $this->getAdapter()->quoteInto('product_id=?', (int)$photoData['product_id']);
		$this->update($data, $where );

	}

	public function deleteProductPhotos($productID = null){
		if(!is_null($productID)){
			$where = $this->getAdapter()->quoteInto('product_id = ?', $productID);
			$this->delete($where);
		}else{
			return false;
		}

	}
	public function deletePhoto($photoID = null){
		if(!is_null($photoID)){
			$where = $table->getAdapter()->quoteInto('id = ?', $photoID);
			$table->delete($where);
		}else{
			return false;
		}
	}

	public function getProductPhotos($productID = null){
		$select = $this->getAdapter()->select()->
			from(array('ph'=>$this->_name),
			array('link'=>'ph.link'));
		if(!is_null($productID)){
			$whereStm = $this->getAdapter()->quoteInto('product_id=?', $productID);
			$select->where($whereStm);
		}

		$resource = $this->getAdapter()->query($select);
		return  $resource->fetchAll();
	}
}
